from sqlalchemy import Column, Integer, String, Text, Boolean
from sqlalchemy.dialects.postgresql import TIMESTAMP as pg_TIMESTAMP
from sqlalchemy.sql import func
from .base import Base

class MetaConfig(Base):
    """
    动态配置信息表 - SQLAlchemy 模型。
    此模型的字段与数据库表的列完全对应。
    """
    __tablename__ = 'meta_config'

    id = Column(Integer, primary_key=True, index=True)
    config_key = Column(String(255), unique=True, nullable=False, index=True)
    config_value = Column(Text)
    
    # 用于分组和排序
    config_type = Column(String(100), nullable=False, default='default', index=True)
    # sort_order = Column(Integer, nullable=False, default=0)

    # 辅助字段
    description = Column(Text)
    is_active = Column(Boolean, nullable=False, default=True)

    # 时间戳字段，依赖数据库自动生成
    created_at = Column(pg_TIMESTAMP(timezone=True), server_default=func.now())
    updated_at = Column(pg_TIMESTAMP(timezone=True), server_default=func.now(), onupdate=func.now())